package com.seo.controller.user.menu;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.seo.pojo.ReturnBody;
import com.seo.service.user.role.sdk.UserRoleService;
import com.seo.utils.Const;
import com.seo.utils.Jurisdiction;

import lombok.extern.slf4j.Slf4j;

/**
 * menucontroller <br/>
 * 
 * @author shibeilei
 * @version 2017.11.30 12:20
 */
@Slf4j
@Controller
@RequestMapping(value = "/menu")
public class UserMenuController {

	@Autowired
	private UserRoleService userRoleService;

	@RequestMapping("/userList")
	@ResponseBody
	public ReturnBody userList(HttpServletRequest request, HttpSession session) {
		log.info("获取菜单...");
		ReturnBody rb = ReturnBody.init();

		Integer roleId = Jurisdiction.getT("roleId", Integer.class);
		if (session.getAttribute(Const.SESSION_MENULIST) == null) {
			rb.run(userRoleService.getUserRoleMenu(roleId));
			if (!rb.isSuccess()) {
				return rb.error();
			}
			session.setAttribute(Const.SESSION_MENULIST, rb.get("menuList", List.class));
			session.setAttribute(Const.SESSION_ROLE, rb.get("role", Map.class));
		} else {
			rb.put("menuList", session.getAttribute(Const.SESSION_MENULIST));
		}
		return rb.success();

	}

	
}
